package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

public class DatabaseManager {
    private static final String URL = "jdbc:mysql://localhost:3306/computer_sales?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8";
    private static final String USER = "root";
    private static final String PASSWORD = "123456";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("MySQL驱动加载成功");
        } catch (ClassNotFoundException e) {
            System.out.println("MySQL驱动加载失败: " + e.getMessage());
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

    public static void initializeDatabase() {
        System.out.println("正在初始化数据库...");

        // 测试数据库连接
        if (!testConnection()) {
            System.out.println("数据库连接失败，无法初始化");
            return;
        }

        // 按依赖顺序创建表
        createUsersTable();              // 1. 用户表（基础）
        createComputerCategoriesTable(); // 2. 分类表
        createSuppliersTable();          // 3. 供应商表
        createCustomersTable();          // 4. 客户表
        createEmployeesTable();          // 5. 员工表
        createComputersTable();          // 6. 电脑表（依赖分类和供应商）
        createSalesTable();              // 7. 销售表（依赖电脑、客户、员工）
        createInventoryRecordsTable();   // 8. 库存记录表（依赖电脑）

        // 插入示例数据
        insertSampleData();
        System.out.println("数据库初始化完成");
    }


    private static void createUsersTable() {
        String sql = "CREATE TABLE IF NOT EXISTS users (" +
                "username VARCHAR(50) PRIMARY KEY," +
                "password VARCHAR(100) NOT NULL," +
                "role ENUM('admin', 'manager', 'staff') NOT NULL DEFAULT 'staff'," +
                "real_name VARCHAR(50) NOT NULL," +
                "phone VARCHAR(20)," +
                "email VARCHAR(100)," +
                "active BOOLEAN DEFAULT true," +
                "last_login_time DATETIME," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
                "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "users");
    }

    private static void createComputerCategoriesTable() {
        String sql = "CREATE TABLE IF NOT EXISTS computer_categories (" +
                "id VARCHAR(20) PRIMARY KEY," +
                "name VARCHAR(50) NOT NULL UNIQUE," +
                "description TEXT," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "computer_categories");
    }

    private static void createSuppliersTable() {
        String sql = "CREATE TABLE IF NOT EXISTS suppliers (" +
                "id VARCHAR(20) PRIMARY KEY," +
                "name VARCHAR(100) NOT NULL UNIQUE," +
                "contact_person VARCHAR(50)," +
                "phone VARCHAR(20)," +
                "email VARCHAR(100)," +
                "address TEXT," +
                "status ENUM('合作中', '暂停', '终止') DEFAULT '合作中'," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "suppliers");
    }

    private static void createCustomersTable() {
        String sql = "CREATE TABLE IF NOT EXISTS customers (" +
                "id VARCHAR(50) PRIMARY KEY," +
                "name VARCHAR(100) NOT NULL," +
                "type ENUM('个人', '企业') DEFAULT '个人'," +
                "phone VARCHAR(20)," +
                "email VARCHAR(100)," +
                "address TEXT," +
                "vip_level ENUM('普通', '银卡', '金卡', '钻石') DEFAULT '普通'," +
                "total_consumption DECIMAL(10,2) DEFAULT 0," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
                "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "customers");
    }

    private static void createEmployeesTable() {
        String sql = "CREATE TABLE IF NOT EXISTS employees (" +
                "id VARCHAR(20) PRIMARY KEY," +
                "name VARCHAR(50) NOT NULL," +
                "role ENUM('销售员', '经理', '管理员', '库存管理员') NOT NULL DEFAULT '销售员'," +
                "phone VARCHAR(20)," +
                "email VARCHAR(100)," +
                "salary DECIMAL(10,2) DEFAULT 0," +
                "hire_date DATE," +
                "status ENUM('在职', '离职') DEFAULT '在职'," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "employees");
    }

    private static void createComputersTable() {
        String sql = "CREATE TABLE IF NOT EXISTS computers (" +
                "id VARCHAR(50) PRIMARY KEY," +
                "category_id VARCHAR(20)," +
                "supplier_id VARCHAR(20)," +
                "brand VARCHAR(100) NOT NULL," +
                "model VARCHAR(100) NOT NULL," +
                "configuration TEXT," +
                "price DECIMAL(10,2) NOT NULL CHECK (price >= 0)," +
                "cost_price DECIMAL(10,2) CHECK (cost_price >= 0)," +
                "stock INT NOT NULL DEFAULT 0 CHECK (stock >= 0)," +
                "min_stock INT DEFAULT 5 CHECK (min_stock >= 0)," +
                "status ENUM('在售', '停售', '缺货') DEFAULT '在售'," +
                "description TEXT," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
                "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
                "FOREIGN KEY (category_id) REFERENCES computer_categories(id) ON DELETE SET NULL," +
                "FOREIGN KEY (supplier_id) REFERENCES suppliers(id) ON DELETE SET NULL" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "computers");
    }

    private static void createSalesTable() {
        String sql = "CREATE TABLE IF NOT EXISTS sales (" +
                "id VARCHAR(50) PRIMARY KEY," +
                "computer_id VARCHAR(50) NOT NULL," +
                "customer_id VARCHAR(50) NOT NULL," +
                "employee_id VARCHAR(20)," +
                "quantity INT NOT NULL CHECK (quantity > 0)," +
                "unit_price DECIMAL(10,2) NOT NULL CHECK (unit_price >= 0)," +
                "total_amount DECIMAL(10,2) NOT NULL CHECK (total_amount >= 0)," +
                "discount DECIMAL(5,2) DEFAULT 1.0 CHECK (discount BETWEEN 0 AND 1)," +
                "final_amount DECIMAL(10,2) NOT NULL CHECK (final_amount >= 0)," +
                "payment_method ENUM('现金', '刷卡', '转账', '微信', '支付宝') DEFAULT '现金'," +
                "sale_time DATETIME NOT NULL," +
                "notes TEXT," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
                "FOREIGN KEY (computer_id) REFERENCES computers(id) ON DELETE RESTRICT," +
                "FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE RESTRICT," +
                "FOREIGN KEY (employee_id) REFERENCES employees(id) ON DELETE SET NULL" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "sales");
    }

    private static void createInventoryRecordsTable() {
        String sql = "CREATE TABLE IF NOT EXISTS inventory_records (" +
                "id VARCHAR(20) PRIMARY KEY," +
                "computer_id VARCHAR(50) NOT NULL," +
                "change_type ENUM('采购入库', '销售出库', '库存调整', '退货入库') NOT NULL," +
                "quantity INT NOT NULL," +
                "unit_price DECIMAL(10,2)," +
                "total_amount DECIMAL(10,2)," +
                "related_id VARCHAR(50)," +
                "record_time DATETIME NOT NULL," +
                "operator VARCHAR(50)," +
                "notes TEXT," +
                "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
                "FOREIGN KEY (computer_id) REFERENCES computers(id) ON DELETE CASCADE" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
        executeUpdate(sql, "inventory_records");
    }


    private static void insertSampleData() {
        System.out.println("正在插入示例数据...");

        // 按依赖顺序插入数据
        insertDefaultUsers();        // 1. 用户数据
        insertCategories();          // 2. 分类数据
        insertSuppliers();           // 3. 供应商数据
        insertEmployees();           // 4. 员工数据
        insertCustomers();           // 5. 客户数据
        insertComputers();           // 6. 电脑数据

        System.out.println("示例数据插入完成");
    }

    private static void insertDefaultUsers() {
        String[] users = {
                "INSERT IGNORE INTO users (username, password, role, real_name, phone, email) VALUES " +
                        "('admin', 'admin123', 'admin', '系统管理员', '13800138000', 'admin@company.com')",

                "INSERT IGNORE INTO users (username, password, role, real_name, phone, email) VALUES " +
                        "('manager', 'manager123', 'manager', '销售经理', '13900139000', 'manager@company.com')",

                "INSERT IGNORE INTO users (username, password, role, real_name, phone, email) VALUES " +
                        "('staff1', 'staff123', 'staff', '销售员张三', '13700137001', 'zhangsan@company.com')",

                "INSERT IGNORE INTO users (username, password, role, real_name, phone, email) VALUES " +
                        "('staff2', 'staff123', 'staff', '销售员李四', '13700137002', 'lisi@company.com')",

                "INSERT IGNORE INTO users (username, password, role, real_name, phone, email) VALUES " +
                        "('warehouse', 'ware123', 'staff', '库存管理员', '13700137003', 'warehouse@company.com')"
        };
        executeBatchUpdates(users, "系统用户");
    }

    private static void insertCategories() {
        String[] categories = {
                "INSERT IGNORE INTO computer_categories (id, name, description) VALUES ('CAT001', '游戏本', '高性能游戏笔记本电脑，适合游戏玩家')",
                "INSERT IGNORE INTO computer_categories (id, name, description) VALUES ('CAT002', '商务本', '轻薄便携商务笔记本电脑，适合办公使用')",
                "INSERT IGNORE INTO computer_categories (id, name, description) VALUES ('CAT003', '台式机', '台式电脑整机，性能稳定')",
                "INSERT IGNORE INTO computer_categories (id, name, description) VALUES ('CAT004', '一体机', '一体式电脑，节省空间')",
                "INSERT IGNORE INTO computer_categories (id, name, description) VALUES ('CAT005', '工作站', '专业图形工作站，适合设计创作')",
                "INSERT IGNORE INTO computer_categories (id, name, description) VALUES ('CAT006', '轻薄本', '超轻薄笔记本电脑，便于携带')"
        };
        executeBatchUpdates(categories, "电脑分类");
    }

    private static void insertSuppliers() {
        String[] suppliers = {
                "INSERT IGNORE INTO suppliers (id, name, contact_person, phone, email, address) VALUES " +
                        "('SUP001', '联想集团', '张经理', '13800138001', 'contact@lenovo.com', '北京市海淀区科学院南路10号')",

                "INSERT IGNORE INTO suppliers (id, name, contact_person, phone, email, address) VALUES " +
                        "('SUP002', '戴尔公司', '李总监', '13900139002', 'sales@dell.com', '上海市浦东新区张江高科技园区')",

                "INSERT IGNORE INTO suppliers (id, name, contact_person, phone, email, address) VALUES " +
                        "('SUP003', '华硕电脑', '王主管', '13700137003', 'support@asus.com', '深圳市南山区科技园南区')",

                "INSERT IGNORE INTO suppliers (id, name, contact_person, phone, email, address) VALUES " +
                        "('SUP004', '惠普公司', '赵经理', '13600136004', 'info@hp.com', '杭州市西湖区文三路创业大厦')",

                "INSERT IGNORE INTO suppliers (id, name, contact_person, phone, email, address) VALUES " +
                        "('SUP005', '苹果公司', '陈顾问', '13500135005', 'contact@apple.com', '北京市朝阳区建国门外大街1号')",

                "INSERT IGNORE INTO suppliers (id, name, contact_person, phone, email, address) VALUES " +
                        "('SUP006', '小米科技', '雷经理', '13400134006', 'partner@xiaomi.com', '北京市海淀区清河中街68号')"
        };
        executeBatchUpdates(suppliers, "供应商");
    }

    private static void insertEmployees() {
        String[] employees = {
                "INSERT IGNORE INTO employees (id, name, role, phone, email, salary, hire_date) VALUES " +
                        "('EMP001', '张三', '销售员', '15000150001', 'zhangsan@company.com', 8000, '2023-01-15')",

                "INSERT IGNORE INTO employees (id, name, role, phone, email, salary, hire_date) VALUES " +
                        "('EMP002', '李四', '经理', '15000150002', 'lisi@company.com', 12000, '2022-06-01')",

                "INSERT IGNORE INTO employees (id, name, role, phone, email, salary, hire_date) VALUES " +
                        "('EMP003', '王五', '库存管理员', '15000150003', 'wangwu@company.com', 7000, '2023-03-20')",

                "INSERT IGNORE INTO employees (id, name, role, phone, email, salary, hire_date) VALUES " +
                        "('EMP004', '赵六', '销售员', '15000150004', 'zhaoliu@company.com', 7500, '2023-05-10')",

                "INSERT IGNORE INTO employees (id, name, role, phone, email, salary, hire_date) VALUES " +
                        "('EMP005', '钱七', '管理员', '15000150005', 'qianqi@company.com', 10000, '2022-12-01')"
        };
        executeBatchUpdates(employees, "员工");
    }

    private static void insertCustomers() {
        String[] customers = {
                "INSERT IGNORE INTO customers (id, name, type, phone, email, address, vip_level, total_consumption) VALUES " +
                        "('CU001', '张三', '个人', '13888888888', 'zhangsan@email.com', '北京市朝阳区建国路88号', '普通', 0)",

                "INSERT IGNORE INTO customers (id, name, type, phone, email, address, vip_level, total_consumption) VALUES " +
                        "('CU002', '李科技有限公司', '企业', '13999999999', 'contact@li-tech.com', '上海市浦东新区张江路1000号', '金卡', 50000)",

                "INSERT IGNORE INTO customers (id, name, type, phone, email, address, vip_level, total_consumption) VALUES " +
                        "('CU003', '王五', '个人', '13777777777', 'wangwu@email.com', '广州市天河区体育西路200号', '银卡', 15000)",

                "INSERT IGNORE INTO customers (id, name, type, phone, email, address, vip_level, total_consumption) VALUES " +
                        "('CU004', '赵氏集团', '企业', '13666666666', 'info@zhaogroup.com', '深圳市南山区科技园500号', '钻石', 120000)",

                "INSERT IGNORE INTO customers (id, name, type, phone, email, address, vip_level, total_consumption) VALUES " +
                        "('CU005', '孙小小', '个人', '13555555555', 'sunxx@email.com', '杭州市西湖区文三路600号', '普通', 8000)",

                "INSERT IGNORE INTO customers (id, name, type, phone, email, address, vip_level, total_consumption) VALUES " +
                        "('CU006', '钱多多网络公司', '企业', '13444444444', 'sales@qiandd.com', '南京市鼓楼区中山路300号', '金卡', 75000)"
        };
        executeBatchUpdates(customers, "客户");
    }

    private static void insertComputers() {
        String[] computers = {
                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C001', 'CAT001', 'SUP001', '联想', '拯救者Y9000P', 'i7-13700H/RTX4060/16GB/1TB SSD/16英寸 2.5K 165Hz', 8999, 7500, 15, 5, '高性能游戏本，畅玩3A大作')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C002', 'CAT002', 'SUP002', '戴尔', 'XPS 13', 'i5-1340P/16GB/512GB SSD/13.4英寸 4K触控屏', 6999, 5800, 8, 3, '超极商务本，轻薄便携')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C003', 'CAT001', 'SUP003', '华硕', 'ROG枪神7', 'i9-13980HX/RTX4080/32GB/2TB SSD/18英寸 2.5K 240Hz', 16999, 14000, 5, 2, '旗舰游戏本，极致性能')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C004', 'CAT003', 'SUP004', '惠普', '暗影精灵9', 'i5-13400F/RTX3060/16GB/1TB SSD/23.8英寸显示器', 5999, 4800, 12, 4, '性价比游戏台式机')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C005', 'CAT004', 'SUP001', '联想', 'AIO 520', 'i5-12400/16GB/512GB SSD/23.8英寸一体机', 4299, 3500, 6, 2, '一体机电脑，节省空间')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C006', 'CAT005', 'SUP005', '苹果', 'Mac Studio', 'M2 Max/32GB/1TB SSD', 16499, 13500, 3, 1, '专业工作站，创意生产力')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C007', 'CAT006', 'SUP006', '小米', 'Redmi Book Pro 15', 'i5-12450H/16GB/512GB SSD/15.6英寸 3.2K 120Hz', 4999, 4200, 10, 3, '高性价比轻薄本')",

                "INSERT IGNORE INTO computers (id, category_id, supplier_id, brand, model, configuration, price, cost_price, stock, min_stock, description) VALUES " +
                        "('C008', 'CAT002', 'SUP002', '戴尔', 'Latitude 5440', 'i7-1355U/16GB/1TB SSD/14英寸 FHD', 7299, 6100, 7, 2, '商务办公笔记本')"
        };
        executeBatchUpdates(computers, "电脑");
    }


    private static void executeBatchUpdates(String[] sqls, String dataType) {
        try (Connection conn = getConnection();
             Statement stmt = conn.createStatement()) {

            int successCount = 0;
            for (String sql : sqls) {
                try {
                    int result = stmt.executeUpdate(sql);
                    if (result >= 0) {
                        successCount++;
                    }
                } catch (SQLException e) {
                }
            }
            System.out.println(dataType + "数据插入完成 (" + successCount + "/" + sqls.length + ")");

        } catch (SQLException e) {
            System.out.println(dataType + "数据插入失败: " + e.getMessage());
        }
    }

    private static void executeUpdate(String sql, String tableName) {
        try (Connection conn = getConnection();
             Statement stmt = conn.createStatement()) {
            stmt.execute(sql);
            System.out.println("表创建成功: " + tableName);
        } catch (SQLException e) {
            System.out.println("表创建失败 " + tableName + ": " + e.getMessage());
        }
    }

    // ==================== 公共方法 ====================

    public static boolean testConnection() {
        try (Connection conn = getConnection()) {
            System.out.println("数据库连接成功！");
            return true;
        } catch (SQLException e) {
            System.out.println("数据库连接失败: " + e.getMessage());
            System.out.println("请检查：");
            System.out.println("   1. MySQL服务是否启动");
            System.out.println("   2. 数据库 'computer_sales' 是否存在");
            System.out.println("   3. 用户名和密码是否正确");
            System.out.println("   4. 连接URL: " + URL);
            return false;
        }
    }

    public static void showDatabaseStatus() {
        System.out.println("\n===== 数据库状态报告 =====");

        if (!testConnection()) {
            return;
        }

        String[] countQueries = {
                "SELECT '用户表' as table_name, COUNT(*) as count FROM users",
                "SELECT '电脑表' as table_name, COUNT(*) as count FROM computers",
                "SELECT '客户表' as table_name, COUNT(*) as count FROM customers",
                "SELECT '销售表' as table_name, COUNT(*) as count FROM sales",
                "SELECT '供应商表' as table_name, COUNT(*) as count FROM suppliers",
                "SELECT '员工表' as table_name, COUNT(*) as count FROM employees",
                "SELECT '分类表' as table_name, COUNT(*) as count FROM computer_categories",
                "SELECT '库存记录表' as table_name, COUNT(*) as count FROM inventory_records"
        };

        try (Connection conn = getConnection();
             Statement stmt = conn.createStatement()) {

            System.out.println("┌───────────────────┬───────┐");
            System.out.println("│ 表名              │ 记录数 │");
            System.out.println("├───────────────────┼───────┤");

            int totalRecords = 0;
            for (String sql : countQueries) {
                try (ResultSet rs = stmt.executeQuery(sql)) {
                    if (rs.next()) {
                        String tableName = rs.getString("table_name");
                        int count = rs.getInt("count");
                        totalRecords += count;
                        System.out.printf("│ %-17s │ %-5d │\n", tableName, count);
                    }
                }
            }

            System.out.println("├───────────────────┼───────┤");
            System.out.printf("│ %-17s │ %-5d │\n", "总计", totalRecords);
            System.out.println("└───────────────────┴───────┘");

        } catch (SQLException e) {
            System.out.println("获取数据库状态失败: " + e.getMessage());
        }
    }

    public static void resetDatabase() {
        System.out.println("警告：此操作将删除所有数据并重新初始化数据库！");
        System.out.print("确认继续？(输入 'YES' 确认): ");

        try {
            java.util.Scanner scanner = new java.util.Scanner(System.in);
            String confirmation = scanner.nextLine();

            if (!"YES".equals(confirmation)) {
                System.out.println("操作已取消");
                return;
            }
        } catch (Exception e) {
            System.out.println("输入读取失败，操作取消");
            return;
        }

        System.out.println("正在重置数据库...");

        // 按依赖关系的逆序删除表
        String[] dropTables = {
                "DROP TABLE IF EXISTS inventory_records",
                "DROP TABLE IF EXISTS sales",
                "DROP TABLE IF EXISTS computers",
                "DROP TABLE IF EXISTS customers",
                "DROP TABLE IF EXISTS employees",
                "DROP TABLE IF EXISTS suppliers",
                "DROP TABLE IF EXISTS computer_categories",
                "DROP TABLE IF EXISTS users"
        };

        try (Connection conn = getConnection();
             Statement stmt = conn.createStatement()) {

            // 禁用外键检查
            stmt.execute("SET FOREIGN_KEY_CHECKS = 0");

            for (String sql : dropTables) {
                try {
                    stmt.execute(sql);
                } catch (SQLException e) {
                }
            }

            // 重新启用外键检查
            stmt.execute("SET FOREIGN_KEY_CHECKS = 1");

            System.out.println("数据库重置完成");

            // 重新初始化
            initializeDatabase();

        } catch (SQLException e) {
            System.out.println("数据库重置失败: " + e.getMessage());
        }
    }

    public static void backupDatabase() {
        System.out.println("数据库备份功能开发中...");
        System.out.println("提示：您可以使用 mysqldump 命令手动备份");
        System.out.println("mysqldump -u root -p computer_sales > backup.sql");
    }
}